<?php

namespace app\common\model;

/**
 * [Manager  法师表]
 * @author [C。]
 * @return html
 */
class Manager extends Base
{
    protected $name = 'manager';
    /**
     * 根据搜索条件获取列表信息
     */
    public function getByConditon($map, $from=0, $size = 4)
    {
        $order = ['id' => 'desc'];

        $result =  $this->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();

        return $result;
    }

    /**
     * 根据条件来获取列表的数据的总数
     * @param array $param
     */
    public function getCountByCondition($map = []) {
        return $this->where($map)->count();
    }
    /**
     * [editData1  根据tel更新数据]
     * @author [C。]
     * @param $data
     * @return mixed
     */
    public function editData1($data)
    {
        if(!is_array($data))
            exception('传递数据不合法');

        $this->allowField(true)->isUpdate(true)->save($data, ['tel' => $data['tel']]);

        return $this->id;
    }


    /**
     * 根据搜索条件获取列表信息
     */
    public function getByConditons($map, $from=0, $size = 5,$field = 'm.id,m.tel,m.username,am.img,am.id memid')
    {
        $order = ['m.info'=>'desc','m.id'=>'asc'];
        $join = [
            ['app_member am','am.tel = m.tel'],
        ];
        $result =  $this->field($field)
            ->alias('m')
            ->join($join)
            ->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取列表数量
     */
    public function getCount($map)
    {
        $join = [
            ['app_member am','am.tel = m.tel'],
        ];
        $result =  $this
            ->alias('m')
            ->join($join)
            ->where($map)
            ->count();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getByConditonsOne($map,$field = 'm.id,m.tel,m.username,am.img,am.id memid')
    {
        $join = [
            ['app_member am','am.tel = m.tel'],
        ];
        $result =  $this->field($field)
            ->alias('m')
            ->join($join)
            ->where($map)
            ->find();

        return $result;
    }
}
